**use dterror_tenure.dta**

***DV: leaderout, Archgos
**mutile leaderouts in one year are censored, only one leader out in a given year
*replace leaderout=. if exit=="Foreign" & leaderout==1
*replace leaderout=. if exit=="Natural Death" & leaderout==1
*replace leaderout=. if exit=="Retired Due to Ill Health" & leaderout==1

***IV: GTD
*gen dterror=.
*replace dterror=dterror70 if year>=1970 & year<=2007 
*replace dterror=dterror08 if year>=2008 & year<=2012
*replace dterror=dterror13 if year>=2013 & year<=2015
*replace dterror=dterror16 if year==2016
*replace dterror=. if year>2016
*replace dterror=0 if year>=1970 & year<=2016 & dterror==.
*gen lndterror=ln(dterror+1)



*** Table 2: main results ***
 logit F.leaderout lndterror age yearinoffice*, nolog cluster(ccode)
outreg using table2.doc , se starlev (10 5 1) starloc(1)  replace
 logit F.leaderout lndterror rgdppc growthrate  cinc polity2 ties_impo war mid age termlimit yearinoffice*    , nolog cluster(ccode)
outreg using table2.doc , se starlev (10 5 1) starloc(1)  replace merge
 logit F.leaderout lndterror rgdppc growthrate cinc polity2 ties_impo war mid age termlimit yearinoffice*    i.ccode , nolog cluster(ccode)
outreg using table2.doc , se starlev (10 5 1) starloc(1)  replace merge
 logit F.leaderout lndterror rgdppc growthrate cinc polity2 ties_impo war mid age termlimit yearinoffice*     i.ccode i.year, nolog cluster(ccode)
outreg using table2.doc , se starlev (10 5 1) starloc(1)  replace merge


 *** Table 3: conditional logit ***
 clogit F.leaderout lndterror age yearinoffice*, group(ccode) vce(robust) nolog
outreg using table3.doc , se starlev (10 5 1) starloc(1)  replace
clogit F.leaderout lndterror rgdppc growthrate cinc polity2 ties_impo war mid age termlimit yearinoffice*     , group(ccode) vce(robust) nolog
outreg using table3.doc , se starlev (10 5 1) starloc(1)  replace merge
clogit F.leaderout lndterror rgdppc growthrate cinc polity2 ties_impo war mid age termlimit yearinoffice*   i.year , group(ccode) vce(robust) nolog
outreg using table3.doc , se starlev (10 5 1) starloc(1)  replace merge


***Table 4: IV  *** 
 
ivprobit f.leaderout  rgdppc growthrate cinc polity2 ties_impo war mid age   termlimit yearinoffice*    (lndterror=  ln_tpop)   , first twostep 
outreg using table4.doc , se starlev (10 5 1) starloc(1)  replace  

 
